import java.awt.Color;
import java.awt.EventQueue;

//Did this add or not cuz of conflict

//this is the part thats different and i want to merge.	5
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JTextField;
import javax.swing.JRadioButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JDesktopPane;

import java.awt.*;
import javax.swing.*;
import java.awt.event.MouseMotionAdapter; 

//Did this add to the thing???
public class NMMWindowwDSilverTest extends JFrame implements MouseListener, MouseMotionListener  {

	
	

	private JFrame frame;
	private JFrame rulesFrame;
	private JTextField txtGameBoardHere;
	  private ImageIcon icon;
	  private JLabel label;
	  private int mouseX; 
	  private int mouseY;
	  private int origX;
	  private int origY;
	  private boolean drag = false; 
	//  JLabel red1, red2, red3, red4, red5, red6, red7, red8, red9;
	//  JLabel blue1, blue2, blue3, blue4, blue5, blue6, blue7, blue8, blue9;
      JLabel red[] = new JLabel[9];//
      JLabel blue[] = new JLabel[9];//
      private int count = 0;//
  	  JTextArea moves = new JTextArea("00");// 
  	  Label label3 = new Label("Moves");//
  	  int board[][] = new int[7][7];//
  	  int isblue = 1; //blue is first
      int ci = 1;
      //current position
  	  int Ex = 0;
  	  int Ey = 0;
  	  int ri = -1;
  	  int bi = -1;
  	  int totalSum;
  	  int a, b;
  	  boolean isMill = false;
  	  
  	  JPanel panel_1 = new JPanel();
  	  
  	  private Player player1;
  	  private Player player2;
  	  //private NameWindow nameWindow;
  	  
  	  //end of stuff i added..
  	  //TODO: figure out where the players are going to input their names...
  	  
		private final ImageIcon RC=new ImageIcon("redcircle.png");
		private final ImageIcon BC=new ImageIcon("bluecircle.png");
		private final ImageIcon RC2=new ImageIcon("redcircle2.png");
		private final ImageIcon BC2=new ImageIcon("bluecircle2.png"); 
  	  JLabel text = new JLabel("Blue First");
  	  //Message = 

	/**
	 * Launch the application.
	 */
  	  
  	  //even more stuff
  	  
	public static void main(String[] args) {
		
	//NameWindow nameWindow = new NameWindow();
	
		
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					NMMWindowwDSilverTest window = new NMMWindowwDSilverTest();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public NMMWindowwDSilverTest() {
		
		getNames();
		
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		
		//NameWindow nm = new NameWindow();
		
		
		frame = new JFrame();
		//frame.setBounds(100, 100, 703, 543);
		frame.setBounds(100, 100, 703, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.NORTH);
		frame.setTitle("NineMensMorris"); //setTitle
		
		JButton btnNewGame = new JButton("New Game");
		btnNewGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("New Game was clicked.");
				if(JOptionPane.showConfirmDialog(null,"Do you want to start a new game","New", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
					System.out.println("New Game was clicked.");
					frame.dispose();
					NMMWindowwDSilverTest window = new NMMWindowwDSilverTest();
					window.frame.setVisible(true);
					count=0;//
					moves.setText("00");//
				}
			}
				
		});
		panel.add(btnNewGame);
		
		JButton btnRules = new JButton("Rules");
		final Rules rule = new Rules();	
		rule.setVisible(false);
		//Rules rule = new Rules();
		//rule.setVisible(false);
		
		
		btnRules.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				rule.setVisible(true);
				
				
				
			}
		});
		panel.add(btnRules);
		
		JButton btnLeaderBoard = new JButton("Leader Board");
		final LeaderBoard  leaderBoard = new LeaderBoard();
		leaderBoard.setVisible(false);
		
		
		btnLeaderBoard.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				//LeaderBoard leaderBoard = new LeaderBoard();
				leaderBoard.setVisible(true);
			}
		});
		panel.add(btnLeaderBoard);
		
		JButton btnQuit = new JButton("Quit");
		btnQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(JOptionPane.showConfirmDialog(null,"Are you sure that you want to quit the game","Quit", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
					
				     System.exit(0);
				}
			}
		});
		panel.add(btnQuit);
		
		
		frame.getContentPane().add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(null);
		
		
//		JPanel panel_3 = new JPanel();
//		panel_3.setBounds(126, 11, 435, 435);
//		panel_1.add(panel_3);
//		panel_3.setLayout(null);
		
		JPanel panel2 = new JPanel();//
		frame.getContentPane().add(panel2, BorderLayout.SOUTH);//
		 
		
		
		moves.setFont(new Font("h",20,20));//
		panel2.add(label3);//
		panel2.add(moves);//
		
		//ImageIcon redcircle=new ImageIcon("redcircle.png");
		//ImageIcon bluecircle=new ImageIcon("bluecircle.png");
		
		text.setBounds(0,215,40,20);
		//panel_1.add(text);
		
		addPieces();
		
		
		ImageIcon boardImage=new ImageIcon("board.gif");
		
		JLabel boardholder = new JLabel(boardImage);
		boardholder.setBounds(126, 11, 435, 435);
		panel_1.add(boardholder);
		
		JLabel name1 = new JLabel(player1.getName(), JLabel.CENTER);
		name1.setBounds(25, 400, 46, 14);
		panel_1.add(name1);
		
		JLabel name2 = new JLabel(player2.getName(), JLabel.CENTER);
		name2.setBounds(606, 400, 46, 14);
		panel_1.add(name2);
		
		for(int i = 0; i<9; i++){
			   red[i].addMouseMotionListener(this); 
			   red[i].addMouseListener(this);
			   blue[i].addMouseMotionListener(this); 
			   blue[i].addMouseListener(this);
		}
	
		//getNames();
	
		
	
	}//end of initialize()

	private void addPieces() {
		// TODO Auto-generated method stub
		red[0] = new JLabel(RC);
		red[0].setBounds(21, 22, 30, 30);
		panel_1.add(red[0]);
		
		red[1] = new JLabel(RC);
		red[1].setBounds(21, 60, 30, 30);
		panel_1.add(red[1]);
		
		red[2] = new JLabel(RC);
		red[2].setBounds(21, 98, 30, 30);
		panel_1.add(red[2]);
		
		red[3] = new JLabel(RC);
		red[3].setBounds(21, 136, 30, 30);
		panel_1.add(red[3]);
		
		red[4] = new JLabel(RC);
		red[4].setBounds(21, 174, 30, 30);
		panel_1.add(red[4]);
		
		red[5] = new JLabel(RC);
		red[5].setBounds(21, 212, 30, 30);
		panel_1.add(red[5]);
		
		red[6] = new JLabel(RC);
		red[6].setBounds(21, 250, 30, 30);
		panel_1.add(red[6]);
		
		red[7] = new JLabel(RC);
		red[7].setBounds(21, 288, 30, 30);
		panel_1.add(red[7]);
		
		red[8] = new JLabel(RC);
		red[8].setBounds(21, 326, 30, 30);
		panel_1.add(red[8]);
		
		blue[0] = new JLabel(BC);
		blue[0].setBounds(636, 22, 30, 30);
		panel_1.add(blue[0]);
		
		blue[1] = new JLabel(BC);
		blue[1].setBounds(636, 60, 30, 30);
		panel_1.add(blue[1]);
		
		blue[2] = new JLabel(BC);
		blue[2].setBounds(636, 98, 30, 30);
		panel_1.add(blue[2]);
		
		blue[3] = new JLabel(BC);
		blue[3].setBounds(636, 136, 30, 30);
		panel_1.add(blue[3]);
		
		blue[4] = new JLabel(BC);
		blue[4].setBounds(636, 174, 30, 30);
		panel_1.add(blue[4]);
		
		blue[5] = new JLabel(BC);
		blue[5].setBounds(636, 212, 30, 30);
		panel_1.add(blue[5]);
		
		blue[6] = new JLabel(BC);
		blue[6].setBounds(636, 250, 30, 30);
		panel_1.add(blue[6]);
		
		blue[7] = new JLabel(BC);
		blue[7].setBounds(636, 288, 30, 30);
		panel_1.add(blue[7]);
		
		blue[8] = new JLabel(BC);
		blue[8].setBounds(636, 326, 30, 30);
		panel_1.add(blue[8]);
		
	}

	/**
	 * method to get names
	 */
	public void getNames(){
		
		//NameWindow nameWindow = new NameWindow();
		
		//String temp = (nameWindow.getName());
		//
		//Player player1 = new Player(temp);
		
		//System.out.println("Players name is : "+player1.getName());
		
		String temp = JOptionPane.showInputDialog(null, "Player 1 enter yo name dawg");
		
		player1 = new Player(temp);
		
		temp = JOptionPane.showInputDialog(null, "Player 2 enter yo name Homes");
		
		player2 = new Player(temp);
		
		
		//TODO do it again for player 2;
		
		
		
		//nameWindow.setVisible(true);
		
		
	}//end of get name
	
	
	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
	    if (drag == true)  
	    { 
	        JComponent jc = (JComponent)e.getSource(); 
	        jc.setLocation(jc.getX()+e.getX(), jc.getY()+e.getY()); 
	    } 


		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
		 JComponent jc = (JComponent)e.getSource();
		 
		 if(jc instanceof JLabel){
			 
			 JLabel jl = (JLabel) jc;
			 
			 if(jl.getIcon().equals(RC)){
				 
				 jl.setIcon(RC2);
				 
				 
			 }
			 else if (jl.getIcon().equals(BC)){
				 jl.setIcon(BC2);
				 
			 }
			 
			 
			 
			 
		 }
		
		
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
		 JComponent jc = (JComponent)e.getSource();	 
		 if(jc instanceof JLabel){
			 
			 JLabel jl = (JLabel) jc;			 
			 if(jl.getIcon().equals(RC2))		 
				 jl.setIcon(RC);			 			 

			 else if (jl.getIcon().equals(BC2))
				 jl.setIcon(BC);
				 
			 
			 
			 
			 
			 
		 }//end of instance of if
		
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
		
		//red[0].removeMouseListener(null);
		//red[0].setLocation(0, 0);
		//red[0].setVisible(false);
		
		
		
		
		
	
		int flag = 0;
		// click the blue one
		if(isblue == 1){
		    for(int i = 0; i < 9; i++){
			   if(e.getSource() == blue[i]){
	    	       drag = true;
	    	       JComponent jc = (JComponent)e.getSource(); 
	    	       origX = jc.getX();
	    	       origY = jc.getY();
	    	       flag = 1;
	    	       bi = i;
			   }
		    }
		    if (flag == 0){
		    	System.out.println("Click the wrong color");
			    JOptionPane.showMessageDialog(this, "Please choose the right color!");
		    }
	    }
		//click the red one
		if(isblue == -1){
			 for(int i = 0; i < 9; i++){
				   if(e.getSource() == red[i]){
		    	       drag = true;
		    	       JComponent jc = (JComponent)e.getSource(); 
		    	       origX = jc.getX();
		    	       origY = jc.getY();
		    	       flag = 1;
		    	       ri = i;
				   }
			  }
			 if (flag == 0){
			    	System.out.println("Click the wrong color");
				    JOptionPane.showMessageDialog(this, "Please choose the right color!");
			    }
		}
		
			
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	    drag = false;
	    JComponent jc = (JComponent)e.getSource();
	    int x = jc.getX()+e.getX();
	    int y = jc.getY()+e.getY();
	    
	    //BLUE
	   if(isblue == 1){
	      if(y >-19 && y < 41){
	    	if(x > 96 && x < 156){
	    		jc.setLocation(126, 11);
	    		if (board[0][0] == 0){
	    		   Ex = 126;
	    		   Ey = 11;
	    		   count++;
	    		   board[0][0] = 1;
	    		}
	    		else{
	    		   if(isMill == false){
	    		       JOptionPane.showMessageDialog(this, "This place has a piece!");
	    		       blue[bi].setBounds(origX,origY, 30, 30);
	    		       Ex = 0;
	    		       Ey = 0;
	    		   }
	    		}
	    	}else if(x > 299 && x < 359){
	    		jc.setLocation(329,11);
	    		if (board[3][0] == 0){
	    		   Ex = 329;
	    		   Ey = 11;
	    		   count++;
	    		   board[3][0] = 1;
	    		}
	    		else{
	    			if(isMill = false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
	    			}
		    	}
	    	} else if(x > 501 && x < 561){
	    		jc.setLocation(531,11);
	    		if(board[6][0] == 0){
	    		  Ex = 531;
	    		  Ey = 11;
	    		  count++;
	    		  board[6][0] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
	    			}
		    	}
	    	} else {
	    		jc.setLocation(origX,origY);
	    		Ex = 0;
	    		Ex = 0;
	    		
	    	}
	    } else if(y >57 && y < 117){
	    	if(x > 172 && x < 232){
	    		jc.setLocation(202, 87);
	    		if(board[1][1] == 0){
	    		  Ex = 202;
	    		  Ey = 87;
	    		  count++;
	    		  board[1][1] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	}else if(x > 299 && x < 359){
	    		jc.setLocation(329,87);
	    		if(board[3][1] == 0){
	    		   Ex = 329;
	    	       Ey = 87;
	    		   count++;
	    		   board[3][1] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else if(x > 425 && x < 485){
	    		jc.setLocation(455,87);
	    		if(board[5][1] == 0){
	    		  Ex = 455;
	    		  Ey = 87;
	    		  count++;
	    		  board[5][1] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else {
	    		jc.setLocation(origX,origY);
	    		Ex = 0;
	    		Ey = 0;
	    	}
	    } else if(y >139 && y < 192){
	    	if(x > 251 && x < 305.5){
	    		jc.setLocation(281, 169);
	    		if(board[2][2] == 0){
	    		   Ex = 281;
	    		   Ey = 169;
	    		   count++;
	    		   board[2][2] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
	    			}
		    	}
	    	}else if(x > 305.5 && x < 353){
	    		jc.setLocation(330,169);
	    		if(board[3][2] == 0){
	    		  Ex = 330;
	    		  Ey = 169;
	    		  count++;
	    		  board[3][2] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else if(x > 353 && x < 406){
	    		jc.setLocation(376,169);
	    		if(board[4][2] == 0){
	    		  Ex = 376;
	    		  Ey = 169;
	    		  count++;
	    		  board[4][2] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else {
	    		jc.setLocation(origX,origY);
	    		Ex = 0;
	    		Ey = 0;
	    	}
	    } else if(y >192 && y < 238){
	    	if(x > 96 && x < 156){
	    		jc.setLocation(126, 215);
	    		if(board[0][3] == 0){
	    		  Ex = 126;
	    		  Ey = 215;
	    		  count++;
	    		  board[0][3] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	}else if(x > 172 && x < 232){
	    		jc.setLocation(202,215);
	    		if(board[1][3] == 0){
	    		   Ex = 202;
	    		   Ey = 215;
	    		   count++;
	    		   board[1][3] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else if(x > 251 && x < 311){
	    		jc.setLocation(281,215);
	    		if(board[2][3] == 0){
	    		  Ex = 281;
	    		  Ey = 215;
	    		  count++;
	    		  board[2][3] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	}else if(x > 346 && x < 406){
	    		jc.setLocation(376,215);
	    		if(board[4][3] == 0){
	    		  Ex = 376;
	    		  Ey = 215;
	    		  count++;
	    		  board[4][3] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else if(x > 425 && x < 485){
	    		jc.setLocation(455,215);
	    		if(board[5][3] == 0){
	    		   Ex = 455;
	    		   Ey = 215;
	    		   count++;
	    		   board[5][3] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else if(x > 501 && x < 561){
	    		jc.setLocation(531,215);
	    		if(board[6][3] == 0){
	    		  Ex = 531;
	    	      Ey = 215;
	    		  count++;
	    		  board[6][3] = 0;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else {
	    		jc.setLocation(origX,origY);
	    		Ex = 0;
		    	Ey = 0;
	    	} 
	    }else if(y >238 && y < 291){
		    if(x > 251 && x < 305.5){
		    	jc.setLocation(281, 261);
		    	if(board[2][4] == 0){
		    	  Ex = 281;
		    	  Ey = 261;
		    	  count++;
		    	  board[2][4] = 1;
		    	}
		    	else{
		    		if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
		    	}
		    }else if(x > 305.5 && x < 353){
		    	jc.setLocation(330,261);
		    	if(board[3][4] == 0){
		    	  Ex = 330;
		    	  Ey = 261;
		    	  count++;
		    	  board[3][4] = 1;
		    	
		    	}
		    	else{
		    		if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
		    	}
		    } else if(x > 353 && x < 406){
		    	jc.setLocation(376,261);
		    	if(board[4][4] == 0){
		    	   Ex = 376;
		    	   Ey = 261;
		    	   count++;
		    	   board[4][4] = 1;
		    	}
		    	else{
		    		if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
		    	}
		    } else {
		    	jc.setLocation(origX,origY);
		    	Ex = 0;
		    	Ey = 0;
		    }
	    }else if(y >310 && y < 370){
		    	if(x > 172 && x < 232){
		    		jc.setLocation(202, 340);
		    		if(board[1][5] == 0){
		    		  Ex = 202;
		    		  Ey = 340;
		    		  count++;
		    		  board[1][5] = 1;
		    		}else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   blue[bi].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	}else if(x > 299 && x < 359){
		    		jc.setLocation(329,340);
		    		if(board[3][5] == 0){
		    		  Ex = 329;
		    		  Ey = 340;
		    		  count++;
		    		  board[3][5] = 1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   blue[bi].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 425 && x < 485){
		    		jc.setLocation(455,340);
		    		if(board[5][5] == 0){
		    		   Ex = 455;
		    		   Ey = 340;
		    		   count++;
		    		   board[5][5] = 1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   blue[bi].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else {
		    		jc.setLocation(origX,origY);
		    		Ex = 0;
		    		Ey = 0;
		    	}
	    } else if(y >386 && y < 446){
	    	if(x > 96 && x < 156){
	    		jc.setLocation(126, 416);
	    		if(board[0][6] == 0){
	    		  Ex = 126;
	    		  Ey = 416;
	    		  count++;
	    		  board[0][6] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	}else if(x > 299 && x < 359){
	    		jc.setLocation(329,416);
	    		if(board[3][6] == 0){
		    		  Ex = 329;
		    		  Ey = 416;
		    		  count++;
		    		  board[3][6] = 1;
		    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else if(x > 501 && x < 561){
	    		jc.setLocation(531,416);
	    		if(board[6][6] == 0){
	    	      Ex = 531;
	    	      Ey = 416;
	    		  count++;
	    		  board[6][6] = 1;
	    		}
	    		else{
	    			if(isMill == false){
		    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		   blue[bi].setBounds(origX,origY, 30, 30);
		    		   Ex = 0;
		    		   Ey = 0;
		    		}
	    		}
	    	} else {
	    		jc.setLocation(origX,origY);
	    		Ex = 0;
	    		Ey = 0;
	    	}
	    } else {
        	jc.setLocation(origX,origY);
        	Ex = 0;
        	Ey = 0;
       }
 
	    //  this is the part thats different and i want to merge.	3
	      
	      //this is the part thats different and i want to merge.	6
	   
	   
	   }
	   if(isblue == -1){
		      if(y >-19 && y < 41){
		    	if(x > 96 && x < 156){
		    		jc.setLocation(126, 11);
		    		if (board[0][0] == 0){
		    		   Ex = 126;
		    		   Ey = 11;
		    		   count++;
		    		   board[0][0] = -1;
		    		}
		    		else{
		    		   if(isMill == false){
		    		      JOptionPane.showMessageDialog(this, "This place has a piece!");
		    		      red[ri].setBounds(origX,origY, 30, 30);
		    		      Ex = 0;
		    		      Ey = 0;
		    		   }
		    		}
		    	}else if(x > 299 && x < 359){
		    		jc.setLocation(329,11);
		    		if (board[3][0] == 0){
		    		   Ex = 329;
		    		   Ey = 11;
		    		   count++;
		    		   board[3][0] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 501 && x < 561){
		    		jc.setLocation(531,11);
		    		if(board[6][0] == 0){
		    		  Ex = 531;
		    		  Ey = 11;
		    		  count++;
		    		  board[6][0] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
   	
		    	
		    	} else {
		    		jc.setLocation(origX,origY);
		    		Ex = 0;
		    		Ex = 0;
		    		
		    	}
		    } else if(y >57 && y < 117){
		    	if(x > 172 && x < 232){
		    		jc.setLocation(202, 87);
		    		if(board[1][1] == 0){
		    		  Ex = 202;
		    		  Ey = 87;
		    		  count++;
		    		  board[1][1] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
		    			}
			    	}
		    	}else if(x > 299 && x < 359){
		    		jc.setLocation(329,87);
		    		if(board[3][1] == 0){
		    		   Ex = 329;
		    	       Ey = 87;
		    		   count++;
		    		   board[3][1] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 425 && x < 485){
		    		jc.setLocation(455,87);
		    		if(board[5][1] == 0){
		    		  Ex = 455;
		    		  Ey = 87;
		    		  count++;
		    		  board[5][1] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
		    			}
			    	}
		    	} else {
		    		jc.setLocation(origX,origY);
		    		Ex = 0;
		    		Ey = 0;
		    	}
		    } else if(y >139 && y < 192){
		    	if(x > 251 && x < 305.5){
		    		jc.setLocation(281, 169);
		    		if(board[2][2] == 0){
		    		   Ex = 281;
		    		   Ey = 169;
		    		   count++;
		    		   board[2][2] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	}else if(x > 305.5 && x < 353){
		    		jc.setLocation(330,169);
		    		if(board[3][2] == 0){
		    		  Ex = 330;
		    		  Ey = 169;
		    		  count++;
		    		  board[3][2] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 353 && x < 406){
		    		jc.setLocation(376,169);
		    		if(board[4][2] == 0){
		    		  Ex = 376;
		    		  Ey = 169;
		    		  count++;
		    		  board[4][2] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
		    			}
			    	}
		    	} else {
		    		jc.setLocation(origX,origY);
		    		Ex = 0;
		    		Ey = 0;
		    	}
		    } else if(y >192 && y < 238){
		    	if(x > 96 && x < 156){
		    		jc.setLocation(126, 215);
		    		if(board[0][3] == 0){
		    		  Ex = 126;
		    		  Ey = 215;
		    		  count++;
		    		  board[0][3] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
		    			}
			    	}
		    	}else if(x > 172 && x < 232){
		    		jc.setLocation(202,215);
		    		if(board[1][3] == 0){
		    		   Ex = 202;
		    		   Ey = 215;
		    		   count++;
		    		   board[1][3] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 251 && x < 311){
		    		jc.setLocation(281,215);
		    		if(board[2][3] == 0){
		    		  Ex = 281;
		    		  Ey = 215;
		    		  count++;
		    		  board[2][3] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	}else if(x > 346 && x < 406){
		    		jc.setLocation(376,215);
		    		if(board[4][3] == 0){
		    		  Ex = 376;
		    		  Ey = 215;
		    		  count++;
		    		  board[4][3] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 425 && x < 485){
		    		jc.setLocation(455,215);
		    		if(board[5][3] == 0){
		    		   Ex = 455;
		    		   Ey = 215;
		    		   count++;
		    		   board[5][3] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 501 && x < 561){
		    		jc.setLocation(531,215);
		    		if(board[6][3] == 0){
		    		  Ex = 531;
		    	      Ey = 215;
		    		  count++;
		    		  board[6][3] = -1;
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else {
		    		jc.setLocation(origX,origY);
		    		Ex = 0;
			    	Ey = 0;
		    	} 
		    }else if(y >238 && y < 291){
			    if(x > 251 && x < 305.5){
			    	jc.setLocation(281, 261);
			    	if(board[2][4] == 0){
			    	  Ex = 281;
			    	  Ey = 261;
			    	  count++;
			    	  board[2][4] = -1;
			    	}
			    	else{
			    		if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
			    	}
			    }else if(x > 305.5 && x < 353){
			    	jc.setLocation(330,261);
			    	if(board[3][4] == 0){
			    	  Ex = 330;
			    	  Ey = 261;
			    	  count++;
			    	  board[3][4] = -1;
			    	}
			    	else{
			    		if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
			    	}
			    } else if(x > 353 && x < 406){
			    	jc.setLocation(376,261);
			    	if(board[4][4] == 0){
			    	   Ex = 376;
			    	   Ey = 261;
			    	   count++;
			    	   board[4][4] = -1;
			    	}
			    	else{
			    		if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
			    	}
			    } else {
			    	jc.setLocation(origX,origY);
			    	Ex = 0;
			    	Ey = 0;
			    }
		    }else if(y >310 && y < 370){
			    	if(x > 172 && x < 232){
			    		jc.setLocation(202, 340);
			    		if(board[1][5] == 0){
			    		  Ex = 202;
			    		  Ey = 340;
			    		  count++;
			    		  board[1][5] = -1;
			    		}else{
			    			if(isMill == false){
				    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
				    		   red[ri].setBounds(origX,origY, 30, 30);
				    		   Ex = 0;
				    		   Ey = 0;
				    		}
			    		}
			    	}else if(x > 299 && x < 359){
			    		jc.setLocation(329,340);
			    		if(board[3][5] == 0){
			    		  Ex = 329;
			    		  Ey = 340;
			    		  count++;
			    		  board[3][5] = -1;
			    		}
			    		else{
			    			if(isMill == false){
				    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
				    		   red[ri].setBounds(origX,origY, 30, 30);
				    		   Ex = 0;
				    		   Ey = 0;
				    		}
			    		}
			    	} else if(x > 425 && x < 485){
			    		jc.setLocation(455,340);
			    		if(board[5][5] == 0){
			    		   Ex = 455;
			    		   Ey = 340;
			    		   count++;
			    		   board[5][5] = -1;
			    		}
			    		else{
			    			if(isMill == false){
				    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
				    		   red[ri].setBounds(origX,origY, 30, 30);
				    		   Ex = 0;
				    		   Ey = 0;
				    		}
			    		}
			    	} else {
			    		jc.setLocation(origX,origY);
			    		Ex = 0;
			    		Ey = 0;
			    	}
		    } else if(y >386 && y < 446){
		    	if(x > 96 && x < 156){
		    		jc.setLocation(126, 416);
		    		if(board[0][6] == 0){
		    		  Ex = 126;
		    		  Ey = 416;
		    		  count++;
		    		  board[0][6] = -1;
		    		  System.out.println(board[0][6]);
		    		}
		    		
		    		//even more more more stuff
		    		
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	}else if(x > 299 && x < 359){
		    	//	jc.setLocation(329,416);
		    		if(board[3][6] == 0){
			    		  Ex = 299;
			    		  Ey = 359;
			    		  count++;
			    		  board[3][6] = -1;
			    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX, origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else if(x > 501 && x < 561){
		    		jc.setLocation(531,416);
		    		if(board[6][6] == 0){
		    	      Ex = 531;
		    	      Ey = 416;
		    		  count++;
		    		  board[6][6] = -1;
		    		  System.out.println(board[6][6]);
		    		}
		    		else{
		    			if(isMill == false){
			    		   JOptionPane.showMessageDialog(this, "This place has a piece!");
			    		   red[ri].setBounds(origX,origY, 30, 30);
			    		   Ex = 0;
			    		   Ey = 0;
			    		}
		    		}
		    	} else {
		    		jc.setLocation(origX,origY);
		    		Ex = 0;
		    		Ey = 0;
		    	}
		    } else {
	        	jc.setLocation(origX,origY);
	        	Ex = 0;
	        	Ey = 0;
	       }
	  }
	    
	    	if((isblue == 1) && Ex != 0 && Ey != 0){
	    	   isblue = -1;
	    	   ci = 0;
	    	}
	    	
	    	if(isblue == -1 && Ex != 0 && Ey != 0 && ci != 0){
	    		isblue = 1;
	    	}
	    	ci = 1;
	    System.out.println(isblue);
  //print out move number
	    String s1;
   	    if (count<=9){
   	    	s1="0"+Integer.toString(count);
   	    }
   	    else{
   	    	s1 = Integer.toString(count);
   	    }
            moves.setText(s1);
           
            checkMills();
		
	}
	
    public void checkMills(){
    	//Row
    	for(a = 0; a<7; a++){
    		totalSum = 0;
    		for(int b = 0; b < 7; b++){
    			if(a != 3){
    			  totalSum = totalSum +board[a][b];
    			  
    			}
    		}
    		
    		if(a == 3){
        		for(b = 0; b < 3; b++){
        			totalSum = totalSum +board[a][b];
        			
        			
        		}
    		}
        		if(totalSum == 3){
            		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
            		isMill = true;
            	}
            	if(totalSum == -3){
            		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");	
            		isMill = true;
            	}
    	}
    	
            a = 3;
            totalSum  = 0;
    		for(b = 4; b < 7; b++){
    			totalSum = totalSum +board[a][b];		
    		}
    	
    	if(totalSum == 3){
    		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
    		isMill = true;
    	}
    	if(totalSum == -3){
    		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");	
    		isMill = true;
    	}
    	
    	//column
    	for(a = 0; a<7; a++){
		   totalSum = 0;
		   for(int b = 0; b < 7; b++){
			  if(a != 3){
			     totalSum = totalSum +board[b][a];
			}
		}
		
		  if(a == 3){
    		  for(b = 0; b < 3; b++){
    			 totalSum = totalSum +board[b][a];
    			
    		  }
		  }
    		
		  if(totalSum == 3){
        		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
        		isMill = true;
        	}
        	if(totalSum == -3){
        		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");	
        		isMill = true;
        	}
	}
	
        a = 3;
        totalSum  = 0;
		for(b = 4; b < 7; b++){
			totalSum = totalSum +board[b][a];		
		}
	
	if(totalSum == 3){
		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
		isMill = true;
	}
	if(totalSum == -3){
		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");
		isMill = true;
	}
}
    
    	
}